package com.cn.gmall.payment.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class AliPayClientConfig {

    //异步调用
    public static String NOTIFY_PAYMENT_URL;

    @Value("${notify_payment_url}")
    public void notify_payment_url(String notify_payment_url) {
        this.NOTIFY_PAYMENT_URL = notify_payment_url;
    }


    //返回到订单地址
    public static String RETURN_ORDER_URL;

    @Value("${return_order_url}")
    public void return_order_url(String return_order_url) {
        this.RETURN_ORDER_URL = return_order_url;
    }


    //同步回调地址
    public static String RETURN_PAYMENT_URL;

    @Value("${return_payment_url}")
    public void return_payment_url(String return_payment_url) {
        this.RETURN_PAYMENT_URL = return_payment_url;
    }




    @Value("${alipay_url}")
    private String alipay_url;

    @Value("${app_private_key}")
    private String app_private_key;

    public static String app_id;
    @Value("${app_id}")
     public  void  appId(String app_id){
         this.app_id=app_id;

     }


    public static String alipay_public_key;
    @Value("${alipay_public_key}")
    public void  alipayPublicKey(String alipay_public_key){
        this.alipay_public_key= alipay_public_key;
    }

    public final static String format = "json";
    public final static String charset = "utf-8";
    public final static String sign_type = "RSA2";


    @Bean
    public AlipayClient alipayClient() {
        AlipayClient alipayClient = new DefaultAlipayClient(
                alipay_url,
                app_id,
                app_private_key,
                format,
                charset,
                alipay_public_key,
                sign_type);
//构造client
        return alipayClient;
    }

}
